var cc__decorate = __decorate;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2BundleManager = require("BundleManager");
var $2JoyStickBall = require("JoyStickBall");
var $2UIManager = require("UIManager");
var $2FlbMathUtil = require("FlbMathUtil");
var $2DataManager = require("DataManager");
var $2AudioManager = require("AudioManager");
var $2KDefine = require("KDefine");
var $2FlbDateTimeUtil = require("FlbDateTimeUtil");
var $2EventsMgr = require("EventsMgr");
var $2UserDataManager = require("UserDataManager");
var $2Jiangshi = require("Jiangshi");
var $2ADManager = require("ADManager");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_ZuqiuUI = /* */function (_cc$Component86) {
  babel_inherits(C, _cc$Component86);
  var _super108 = babel_createSuper(C);
  function C() {
    var _this255;
    babel_classCallCheck(this, C);
    _this255 = _super108.apply(this, arguments);
    _this255.player = null;
    _this255.joyStick = null;
    _this255.speed = 400;
    _this255.dfzdrooms = null;
    _this255.curr_time = 0;
    _this255.total_time = 3;
    _this255.djs_num = null;
    _this255.game_time = null;
    _this255.yx_time = 0;
    _this255.hbdian = null;
    _this255.timeInfo = null;
    return _this255;
  }
  babel_createClass(C, [{
    key: "onLoad",
    value: function onLoad() {
      var _this256 = this;
      $2UIManager.default.instance.hideUI("MoneyPanelUI");
      this.dfzdrooms = cc.find("dfzdrooms", this.node);
      this.joyStick = cc.find("JoyStick", this.node);
      this.djs_num = cc.find("djs", this.node);
      this.game_time = cc.find("game_time", this.node);
      this.hbdian = cc.find("hbdian", this.node);
      this.player = cc.instantiate($2BundleManager.default.instance.getBundleRes("Prefab", "Zuqiu/PlayerBall", cc.Prefab));
      this.player.parent = this.node;
      $2EventsMgr.EventsManager.on("play_sp", function () {
        _this256.player && _this256.player.getComponent(sp.Skeleton).setAnimation(0, "run2", true);
      });
      $2EventsMgr.EventsManager.on("game_over", function () {
        _this256.init();
      });
      $2EventsMgr.EventsManager.on("fuhuo", function () {
        _this256.fuhuo_init();
      });
      $2EventsMgr.EventsManager.on("gameOver", function () {
        _this256.game_over();
      });
      this.init();
      this.initPlatform();
    }
  }, {
    key: "onEnable",
    value: function onEnable() {
      $2AudioManager.default.instance.resumeBgm();
      $2UIManager.default.instance.hideUI("MoneyPanelUI");
      $2AudioManager.default.instance.playMusic($2KDefine.AudioName.bgm4, true);
    }
  }, {
    key: "onDisable",
    value: function onDisable() {
      $2UIManager.default.instance.showUI("MoneyPanelUI");
    }
  }, {
    key: "initPlatform",
    value: function initPlatform() {
      switch ($2ADManager.default.instance.sdkType) {
        case $2ADManager.SDK_TYPE.WeChat:
          $2ADManager.default.instance.showNative(0);
          $2ADManager.default.instance.showNative(5);
      }
    }
  }, {
    key: "init",
    value: function init() {
      var _this257 = this;
      if (this.game_time) {
        $2ADManager.default.instance.recorderStart();
        $2UserDataManager.default.instance.getTime1Info();
        this.player.getComponent(sp.Skeleton).setAnimation(0, "run2", true);
        this.game_time.getComponent(cc.Label).string = $2FlbDateTimeUtil.FlbDateTimeUtil.sjformate(0);
        $2DataManager.default.instance.cur_hp = $2DataManager.default.instance.total_hp;
        this.djs_num.active = true;
        this.game_time.active = false;
        this.player.setPosition(0, -90);
        this.djs_num.setPosition(0, 115);
        this.joyStick.zIndex = 99;
        this.joyStick.setPosition(this.hbdian.position);
        this.joyStick.getChildByName("Stick").setPosition(cc.v2(0, 0));
        this.joyStick.getComponent($2JoyStickBall.default).dir = cc.v2(0, 0);
        for (var _e135 = 0; _e135 < this.dfzdrooms.childrenCount; _e135++) {
          this.dfzdrooms.children[_e135].removeAllChildren();
        }
        this.djs(function () {
          _this257.djs_num.active = false;
          $2DataManager.default.instance.is_over = false;
          $2DataManager.default.instance.yx_start_time = Date.now();
          _this257.game_time.active = true;
        });
      }
    }
  }, {
    key: "fuhuo_init",
    value: function fuhuo_init() {
      var _this258 = this;
      if (this.game_time) {
        $2ADManager.default.instance.recorderStart();
        $2UserDataManager.default.instance.getTime1Info();
        this.player.getComponent(sp.Skeleton).setAnimation(0, "run2", true);
        this.game_time.getComponent(cc.Label).string = $2FlbDateTimeUtil.FlbDateTimeUtil.sjformate(0);
        $2DataManager.default.instance.cur_hp = $2DataManager.default.instance.total_hp;
        this.djs_num.active = true;
        this.game_time.active = false;
        this.player.setPosition(0, -90);
        this.djs_num.setPosition(0, 115);
        this.joyStick.zIndex = 99;
        this.joyStick.setPosition(this.hbdian.position);
        this.joyStick.getChildByName("Stick").setPosition(cc.v2(0, 0));
        this.joyStick.getComponent($2JoyStickBall.default).dir = cc.v2(0, 0);
        for (var _e136 = 0; _e136 < this.dfzdrooms.childrenCount; _e136++) {
          this.dfzdrooms.children[_e136].removeAllChildren();
        }
        this.djs(function () {
          _this258.djs_num.active = false;
          $2DataManager.default.instance.is_over = false;
          $2DataManager.default.instance.yx_start_time = Date.now() - 1e3 * $2DataManager.default.instance.offset_time;
          _this258.game_time.active = true;
        });
      }
    }
  }, {
    key: "game_over",
    value: function game_over() {
      var _this259 = this;
      if (this.player) {
        $2DataManager.default.instance.offset_time = this.yx_time;
        this.player.getComponent(sp.Skeleton).setAnimation(0, "die", true);
        $2DataManager.default.instance.is_over = true;
        this.unscheduleAllCallbacks();
        $2AudioManager.default.instance.playEffect($2KDefine.AudioName.jieshu);
        this.scheduleOnce(function () {
          var e = null;
          if ($2DataManager.default.instance.fuhuo_flag) {
            e = cc.instantiate($2BundleManager.default.instance.getBundleRes("Prefab", "Zuqiu/JjdfEndBall", cc.Prefab));
            $2DataManager.default.instance.fuhuo_flag = false;
          } else {
            e = cc.instantiate($2BundleManager.default.instance.getBundleRes("Prefab", "Zuqiu/FuhuoBall", cc.Prefab));
          }
          e.parent = _this259.node;
          e.zIndex = 100;
        }, 2);
      }
    }
  }, {
    key: "update_time",
    value: function update_time() {
      var e = Date.now();
      var t = Math.floor((e - $2DataManager.default.instance.yx_start_time) / 1e3);
      this.yx_time = t;
      this.game_time.getComponent(cc.Label).string = $2FlbDateTimeUtil.FlbDateTimeUtil.sjformate(t);
    }
  }, {
    key: "djs",
    value: function djs(e) {
      var _this260 = this;
      var t = 3;
      this.djs_num.getComponent(cc.Label).string = t + "";
      this.schedule(function () {
        if (t <= 0) {
          $2AudioManager.default.instance.playEffect($2KDefine.AudioName.djs2);
          return void (e && e());
        }
        _this260.djs_num.getComponent(cc.Label).string = t + "";
        t--;
        $2AudioManager.default.instance.playEffect($2KDefine.AudioName.djs1);
      }, 1, t, 0);
    }
  }, {
    key: "createJfzd",
    value: function createJfzd(e, t) {
      var a = cc.instantiate($2BundleManager.default.instance.getBundleRes("Prefab", "Zuqiu/jiangshi", cc.Prefab));
      a.parent = this.dfzdrooms.children[e];
      a.getComponent($2Jiangshi.default).setType(t);
    }
  }, {
    key: "fire",
    value: function fire(e) {
      var t = Date.now();
      var a = Math.floor((t - $2DataManager.default.instance.yx_start_time) / 1e3);
      for (var _o5 = 0; _o5 < $2UserDataManager.default.instance.time1Info.length; _o5++) {
        var _e137 = $2UserDataManager.default.instance.time1Info[_o5];
        if (a < _e137.gametime) {
          this.timeInfo = _e137;
          break;
        }
      }
      this.total_time = $2FlbMathUtil.MathUtil.getRandom(this.timeInfo.skilltime[0], this.timeInfo.skilltime[1]);
      this.curr_time += e;
      if (this.curr_time < this.total_time) {
        return;
      }
      this.curr_time = 0;
      var n = [];
      for (var _o6 = 0; _o6 < this.timeInfo.count.length; _o6++) {
        n.push(this.timeInfo.count[_o6][1]);
      }
      var i = $2FlbMathUtil.MathUtil.getRand(n);
      var s = undefined;
      for (var _o7 = 0; _o7 < this.timeInfo.count[i][0]; _o7++) {
        var _e138 = $2FlbMathUtil.MathUtil.getRandomInt(0, this.dfzdrooms.childrenCount - 1);
        if (null != _e138) {
          var _t85 = Math.abs(_e138 - s);
          for (; _t85 < 2;) {
            _e138 = $2FlbMathUtil.MathUtil.getRandomInt(0, this.dfzdrooms.childrenCount - 1);
            _t85 = Math.abs(_e138 - s);
          }
        }
        s = _e138;
        this.createJfzd(_e138, this.timeInfo.speed);
      }
    }
  }, {
    key: "update",
    value: function update(e) {
      if ($2DataManager.default.instance.is_over) {
        return;
      }
      this.update_time();
      this.fire(e);
      if (this.joyStick.getComponent($2JoyStickBall.default).dir.mag() < .5) {
        return;
      }
      var t = this.joyStick.getComponent($2JoyStickBall.default).dir.x * this.speed * e;
      var a = this.joyStick.getComponent($2JoyStickBall.default).dir.y * this.speed * e;
      this.player.x += t;
      this.player.y += a;
      var n = Math.atan2(this.joyStick.getComponent($2JoyStickBall.default).dir.y, this.joyStick.getComponent($2JoyStickBall.default).dir.x);
      var i = cc.misc.radiansToDegrees(n);
      this.player.scaleX = i > 90 && i < 180 || i < -90 && i > -180 ? -.2 : .2;
      this.player.x > cc.winSize.width / 2 - this.player.width / 2 * this.player.scaleX && (this.player.x = cc.winSize.width / 2 - this.player.width / 2 * this.player.scaleX);
      this.player.x < -cc.winSize.width / 2 - this.player.width / 2 * this.player.scaleX && (this.player.x = -cc.winSize.width / 2 - this.player.width / 2 * this.player.scaleX);
      this.player.y > cc.winSize.height / 2 - this.player.height * this.player.scaleY && (this.player.y = cc.winSize.height / 2 - this.player.height * this.player.scaleY);
      this.player.y < -cc.winSize.height / 2 && (this.player.y = -cc.winSize.height / 2);
    }
  }]);
  return C;
}(cc.Component);
def_ZuqiuUI = cc__decorate([ccp_ccclass], def_ZuqiuUI);
exports.default = def_ZuqiuUI;